package com.habdqn.easybuy.web.front;

import com.habdqn.easybuy.entity.News;
import com.habdqn.easybuy.entity.Product;
import com.habdqn.easybuy.entity.ProductCategory;
import com.habdqn.easybuy.service.NewsService;
import com.habdqn.easybuy.service.ProductCategoryService;
import com.habdqn.easybuy.service.ProductService;
import com.habdqn.easybuy.service.impl.NewsServiceImpl;
import com.habdqn.easybuy.service.impl.ProductCategoryServiceImpl;
import com.habdqn.easybuy.service.impl.ProductServiceImpl;
import com.habdqn.easybuy.util.Page;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author Xing.Jiejian
 * @date 2020/11/28
 */
@WebServlet(name = "IndexServlet",urlPatterns = "/index")
public class IndexServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        // 特价商品(获取最近商品)
        ProductService productService = new ProductServiceImpl();
        Page<Product> productPage = productService.queryByPage(null,new Page<Product>(1,12),false);

        // 新闻
        NewsService newsService = new NewsServiceImpl();
        Page<News> newsPage = newsService.queryByPageWithUser(null,new Page<>(1,10));

        request.setAttribute("productPage",productPage);
        request.setAttribute("newsPage",newsPage);
        request.getRequestDispatcher("/WEB-INF/front/index.jsp").forward(request,response);
    }
}
